﻿using OBS;
using OBS.Model;
using System.IO;

namespace Armon.Lib.Net.Obs
{
    public class HuaweiCloudObsUploader : IObsUploader
    {
        private readonly ObsOptions options;
        private readonly ObsClient client;

        public HuaweiCloudObsUploader(ObsOptions options)
        {
            this.options = options;
            var config = new ObsConfig
            {
                Endpoint = options.Endpoint,
            };
            client = new ObsClient(options.AccessKey, options.SecretKey, config);
        }

        public PutObjectResponse Push(string objectKey, string file)
        {
            if (!File.Exists(file))
            {
                return new PutObjectResponse();
            }

            var request = new PutObjectRequest()
            {
                BucketName = options.BucketName,
                ObjectKey = objectKey,
                FilePath = file,
            };
            return client.PutObject(request);
        }
    }
}
